class Solution {
public:
    vector<int> getSumAbsoluteDifferences(vector<int>& nums) {
        int n = nums.size();
        vector<int>sum(n + 1);
        for (int i = 0; i < n; i++)
        {
            sum[i + 1] = sum[i] + nums[i];
        }
        vector<int> result;
        for (int i = 0; i < n; i++)
        {
            int target = nums[i];
            int left = target * i - sum[i];
            int right = sum[n] - sum[i] - target * (n - i);
            result.push_back(left + right);
        }
        return result;
    }
};